package cn.fl.etc.service.impl;

import cn.fl.etc.constant.EtcConstant;
import cn.fl.etc.service.IEtcLvlRecTraceService;
import cn.fl.etc.transform.EtcLvlRecTraceVOTransform;
import cn.fl.etc.vo.EtcLvlRecTraceVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.mcr.util.DesensitizationUtil;
import cn.lionbridgecapital.loan.model.base.Pager;
import cn.lionbridgecapital.loan.model.dto.etc.EtcLvlRecTraceDTO;
import cn.lionbridgecapital.loan.model.exception.BaseException;
import cn.lionbridgecapital.loan.model.exception.BaseExceptionConstant;
import cn.lionbridgecapital.loan.model.utils.CollectionUtils;
import cn.lionbridgecapital.loan.model.utils.SensitiveInfoUtils;
import cn.lionbridgecapital.loan.model.utils.StringUtils;
import cn.lionbridgecapital.loan.service.api.etc.IEtcLvlRecTraceApiService;
import cn.lionbridgecapital.loan.utils.BaseLogUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @类名称 EtcLvlRecTraceServiceImpl
 * @类描述
 * @作者 yl
 * @创建时间 2020年10月12日 11时11分
 * @版本 1.00
 * @修改记录 <pre><pre>
 */
@Service
public class EtcLvlRecTraceServiceImpl implements IEtcLvlRecTraceService {

    /**
     * 日志
     */
    private static final Logger logger = LoggerFactory.getLogger(EtcLvlRecTraceServiceImpl.class);

    @Autowired
    private IEtcLvlRecTraceApiService etcLvlRecTraceApiService;


    @Override
    public EtcLvlRecTraceVO selectById(Long id) throws BaseException {
        if(StringUtils.isEmpty(id)){
            BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "获取对象主键不能为空!");
        }
        //TODO 业务逻辑
        EtcLvlRecTraceDTO dto = null;//this.自定义ApiService.selectEtcLvlRecTraceDTOById(id);
        return EtcLvlRecTraceVOTransform.toVO(dto);
    }

    @Override
    public Long add(EtcLvlRecTraceVO entity) throws BaseException{
        if(null == entity){
            BaseLogUtils.info(logger, "add", "新增对象不存在!");
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"新增对象不存在!");
        };
        //return this.etcLvlRecTraceApiService.add(EtcLvlRecTraceVOTransform.toDTO(entity));
        //TODO 业务逻辑
        return null;
    }

    @Override
    public boolean removeById(Long id) throws BaseException{
        if(StringUtils.isEmpty(id)){
            BaseLogUtils.info(logger, "removeById", "删除对象主键不能为空!");
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"删除对象主键不能为空!");
        };
        //return this.etcLvlRecTraceApiService.removeEtcLvlRecTraceDTOById(id);
        //TODO 业务逻辑
        return false;
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
        if(CollectionUtils.isEmpty(ids)){
            BaseLogUtils.info(logger, "removeByIds", "删除主键参数集合不能为空!", CurrentThreadContext.getCurrentUserName());
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"删除对象主键不能为空!");
        };
        return false;
    }

    @Override
    public boolean modify(EtcLvlRecTraceVO entity) throws BaseException{
        if(null == entity){
            BaseLogUtils.info(logger, "modify", "修改对象不能为空!");
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"修改对象不能为空!");
        };
        //return this.etcLvlRecTraceApiService.modifyEtcLvlRecTraceDTO(EtcLvlRecTraceVOTransform.toDTO(entity));
        //TODO 业务逻辑
        return false;
    }

    @Override
    public Pager searchListPage(Pager page) throws BaseException{
        if(null == page){
            page = new Pager();
        }
        Pager pager = etcLvlRecTraceApiService.searchListPage(page);
        List<EtcLvlRecTraceDTO> list = (List<EtcLvlRecTraceDTO>) pager.getResultList();
        if (CollectionUtils.isNotEmpty(list)){
            List<EtcLvlRecTraceVO> listVO = new ArrayList<>();
            for(EtcLvlRecTraceDTO dto : list) {
                if(EtcConstant.RskLvlCd.pass.equals(dto.getRskLvlCd())){
                    dto.setErrorRemark(EtcConstant.RskLvlCd.passLabel);
                }else if(EtcConstant.RskLvlCd.refuse.equals(dto.getRskLvlCd())){
                    dto.setErrorRemark(EtcConstant.RskLvlCd.refuseLabel);
                }
                dto.setCstNm(DesensitizationUtil.name(dto.getCstNm()));
                dto.setCertNo(SensitiveInfoUtils.idCard(dto.getCertNo()));
                dto.setMp(SensitiveInfoUtils.mobilePhone(dto.getMp()));
                dto.setVerifyMp(SensitiveInfoUtils.mobilePhone(dto.getVerifyMp()));
                listVO.add(EtcLvlRecTraceVOTransform.toVO(dto));
            }
            pager.setResultList(listVO);
        }
        return pager;
    }
}
